/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PlanPanel.java
 *
 * The Panel within Plan Window (PlanFrame) that contains Insert/Merge Plan.
 *
 * --- Last Update: 5/18/2010 1:39 AM ---
 *
 * Update Notes 5/18/2010 1:39 AM by Adrian Wijasa:
 * Now throws ColumnNotConfiguredException.
 *
 * Update Notes 4/23/2010 8:57 PM by Adrian Wijasa:
 * Now disables PlanFrame before saving the plan into a file.
 *
 * Update Notes 4/22/2010 9:59 PM by Adrian Wijasa:
 * Added a logic to save the Plan into a file.
 *
 * Update Notes 4/18/2010 6:54 PM by Adrian Wijasa:
 * This class can now work with Java 5.
 *
 * Created on Apr 15, 2010, 10:15:17 PM
 *
 * CSV Loader
 * Copyright 2007, 2009, 2010 Adrian Wijasa
 *
 * This file is part of CSV Loader.
 *
 * CSV Loader is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * CSV Loader is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with CSV Loader.  If not, see <http://www.gnu.org/licenses/>.
 */

package panels;

import csv.ColumnNotConfiguredException;
import forms.FileChooserFrame;
import forms.Main;
import java.sql.SQLException;

/**
 *
 * @author matianyuan
 */
public class PlanPanel extends javax.swing.JPanel {

    /** Creates new form PlanPanel */
    public PlanPanel( Main main ) throws ClassNotFoundException, ColumnNotConfiguredException, SQLException {
        this.main = main;
        initComponents();
        textPane.setText( main.csvPanel.currentImage.getPlan().getPlan() );
        textPane.select( 0, 0 );
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        scrollPane = new javax.swing.JScrollPane();
        textPane = new javax.swing.JTextPane();
        saveLabel = new javax.swing.JLabel();

        textPane.setEditable(false);
        scrollPane.setViewportView(textPane);

        saveLabel.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        saveLabel.setForeground(new java.awt.Color(0, 102, 255));
        saveLabel.setText("Save");
        saveLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                saveLabelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                saveLabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                saveLabelMouseExited(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(374, 374, 374)
                .add(saveLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 28, Short.MAX_VALUE)
                .add(378, 378, 378))
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(scrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 756, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(scrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 505, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(saveLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void saveLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saveLabelMouseClicked
        saveLabel.setForeground( main.red );

        main.planFrame.setEnabled( false );
        main.popUpFileChooser( FileChooserFrame.SAVE_PLAN );
}//GEN-LAST:event_saveLabelMouseClicked

    private void saveLabelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saveLabelMouseExited
        saveLabel.setForeground( main.blue );
}//GEN-LAST:event_saveLabelMouseExited

    private void saveLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saveLabelMouseEntered
        saveLabel.setForeground( main.black );
}//GEN-LAST:event_saveLabelMouseEntered


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel saveLabel;
    private javax.swing.JScrollPane scrollPane;
    private javax.swing.JTextPane textPane;
    // End of variables declaration//GEN-END:variables

    private Main main;
}
